package com.shahe.GirlsDay.MyView;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
import com.shahe.GirlsDay.R;

public class ChartView extends View {

	private Paint paint;

	public ChartView(Context context) {
		super(context);
		paint = new Paint();
		paint.setAntiAlias(true);
	}

	public void onDraw(Canvas canvas) {
		canvas.drawColor(Color.WHITE);
		drawAxis(canvas);
		drawChart(canvas);
	}

	public void drawAxis(Canvas canvas) {
		paint.setColor(getResources().getColor(R.color.chartLine));
		paint.setStrokeWidth(2);
		canvas.drawLine(50, 300, 310, 300, paint);// 横线
		canvas.drawLine(50, 20, 50, 300, paint);// 竖线

		paint.setColor(getResources().getColor(R.color.chartDottedLine));
		paint.setStrokeWidth(1);
		canvas.drawLine(50, 250, 310, 250, paint);// 横虚线
		canvas.drawLine(50, 200, 310, 200, paint);// 横虚线
		canvas.drawLine(50, 150, 310, 150, paint);// 横虚线
		canvas.drawLine(50, 100, 310, 100, paint);// 横虚线
		canvas.drawLine(50, 50, 310, 50, paint);// 横虚线

		canvas.drawLine(100, 20, 100, 300, paint);// 竖虚线
		canvas.drawLine(150, 20, 150, 300, paint);// 竖虚线
		canvas.drawLine(200, 20, 200, 300, paint);// 竖虚线
		canvas.drawLine(250, 20, 250, 300, paint);// 竖虚线

		int x = 100;
		int y = 250;

		paint.setColor(Color.BLACK);
		for (int i = 0; i < 4; i++) {
			// 横线
			canvas.drawText(i + 1 + "", x, 320, paint);
			x += 50;
		}
		for (int i = 0; i < 5; i++) {
			// 竖线
			canvas.drawText(50 * (i + 1) + "", 20, y, paint);
			y -= 50;
		}

	}

	// 画曲线
	void drawChart(Canvas canvas) {
		paint.setColor(getResources().getColor(R.color.chartLine));
		paint.setStrokeWidth(2);
		canvas.drawLine(50, 300, 100, 250, paint);// 横+50,竖-50；
		canvas.drawLine(100, 250, 150, 200, paint);
		canvas.drawLine(150, 200, 200, 250, paint);
		canvas.drawLine(200, 250, 250, 200, paint);
	}

}
